/**
 * 模块：医院入驻平台-UserAccount
 */
package design.onekey.controller;

import design.onekey.annotation.LoginUser;
import design.onekey.base.BaseEntity;
import design.onekey.base.Response;
import design.onekey.model.dto.UserInfoDto;
import design.onekey.model.UserAccount;
import design.onekey.model.dto.UserAccountDto;
import design.onekey.model.dto.UserWithOrgRoleDto;
import design.onekey.service.IUserAccountService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

/**
* @Description: UserAccountcontroller类
* @author
* @date 2020-06-05 04:03:19
* @version V1.0
 */
@RestController
@RequestMapping("/api/userAccount")
public class UserAccountController {

	/**
	 * iUserAccountService服务注入
	 */
	@Autowired
	private IUserAccountService iUserAccountService;

	/**
	* @Description: 分页查询表格
	* @param @return
	* @return BaseEntity
	* @throws
	*/
	@RequestMapping(value = "/getTableList",method = RequestMethod.POST)
	public Response getTableList(@RequestBody UserAccount model, @LoginUser UserInfoDto userInfoDto)
	{
		BaseEntity result = new BaseEntity();
		result = iUserAccountService.tablePagingQueryByAuthority(model,userInfoDto);
		return Response.success(result);
	}

	/**
	* @Description: 获取详细信息
	* @param id
	* @param @return  BaseEntity
	* @return
	* @throws
	*/
	@RequestMapping(value = "/getDetail",method = RequestMethod.GET)
	public Response getDetail(@RequestParam Long id) throws Exception
	{
		BaseEntity result = iUserAccountService.getDetail(id);
		return Response.success(result);
	}

	/**
	* @throws Exception
	* @Description: 新增
	* @param UserAccount
	* @return BaseEntity
	* @throws
	*/
	@RequestMapping(value = "/insert",method = RequestMethod.POST)
	public Response insert(@RequestBody UserWithOrgRoleDto model, @LoginUser UserInfoDto userInfoDto) throws Exception
	{
		BaseEntity result = iUserAccountService.insert(model,userInfoDto);
		return Response.success(result.getStatusMsg());
	}

	/**
	* @throws Exception
	* @Description: 更新
	* @param UserAccount
	* @return  BaseEntity
	* @throws
	*/
	@RequestMapping(value = "/update",method = RequestMethod.POST)
	public Response update(@RequestBody UserWithOrgRoleDto model, @LoginUser UserInfoDto userInfoDto) throws Exception
	{
		BaseEntity result = iUserAccountService.update(model,userInfoDto);
		return Response.success(result.getStatusMsg());
	}

	/**
	* @Description: 单条删除
	* @param id
	* @return  BaseEntity
	* @throws
	*/
	@RequestMapping(value = "/delete",method = RequestMethod.GET)
	public Response delete(@RequestParam Long id)
	{
		BaseEntity result = iUserAccountService.delete(id);
		return Response.success(result.getStatusMsg());
	}

	/**
	* @Description: 批量删除
	* @param UserAccount
	* @return BaseEntity
	* @throws
	*/
	@RequestMapping(value = "/deletebatch",method = RequestMethod.POST)
	public Response deletebatch(@RequestBody List<Long> ids)
	{
		BaseEntity result = iUserAccountService.deleteBatch(ids);
		return Response.success(result.getStatusMsg());
	}

	/**
	 * @Method resetPwd
	 * @Author zhangcheng
	 * @Version  1.0
	 * @Description 根据用户id重置密码
	 * @Return com.baiyyy.yfz.base.BaseEntity
	 * @Exception
	 * @Date 2020-6-12 9:13
	 */
	@RequestMapping(value = "/resetPwd",method = RequestMethod.GET)
	public Response resetPwd(@RequestParam Long id){
		BaseEntity result = iUserAccountService.resetPwd(id);
		return Response.success(result.getStatusMsg());
	}

	/**
	 * @Title: changePwd
	 * @Description: 修改密码
	 * @param userAccount
	 * @return
	 * @author blcloak
	 * @date 2020-06-12 01:20:47
	 */
	@RequestMapping(value = "/changePwd",method = RequestMethod.POST)
	public Response changePwd(@RequestBody UserAccountDto userAccountDto, @LoginUser UserInfoDto userInfoDto) {
		BaseEntity result = this.iUserAccountService.changePwd(userAccountDto, userInfoDto);
		return Response.success(result.getStatusMsg());
	}

	/**
	 * @Title: updateStatus
	 * @Description: 账号启用停用
	 * @param userAccount
	 * @return
	 * @author blcloak
	 * @date 2020-06-23 07:48:08
	 */
	@RequestMapping(value = "/updateStatus",method = RequestMethod.POST)
	public Response updateStatus(@RequestBody UserAccount userAccount) {
		BaseEntity result = this.iUserAccountService.updateStatus(userAccount);
		return Response.success(result.getStatusMsg());
	}
}
